<template>
	<view>
		<uni-segmented-control id="tab" :current="current" :values="items" @clickItem="onClickItem" styleType="text"
			activeColor="#2DABF6"></uni-segmented-control>
		<view class="content">
			
			<view v-show="current === 0">
				<view class="tablist" v-for="(v,i) in applyData"  key="v.mun" @click="detail(v)">
					
					<view>{{v.type}}申请</view>
					<view>{{v.department_name}}-{{v.post_name}}<!-- --{{v.name}} --></view>
					<view>{{v.applytime}}</view>
					<text>直接领导审核</text>

				</view>
			</view>
			<view v-show="current === 1">
				<view class="tablist" v-for="(v,i) in applyData"  key="v.mun" @click="detail(v)">
					<view>{{v.type}}申请</view>
					<view>{{v.department_name}}-{{v.post_name}}<!-- --{{v.name}} --></view>
					<view>{{v.applytime}}</view>
					<text>审核完成</text>

				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		computed,
		reactive,
		toRefs,
		onMounted
	} from 'vue';
	import $http from "../../utils/http.js"
	import store from '~@/store/index.js'
	export default {
		setup(props,context) {
			let data = reactive({
				items: ['待办', '已办'],
				current: 0,
				mystate: '待审核',
				onClickItem(e) {					
					if (e.currentIndex == 1) {
						data.current = e.currentIndex;
						data.mystate = '已审核'
						data.getApplyData()					

					} else {
						data.current = e.currentIndex;
						data.mystate = '待审核'
						data.getApplyData()
						
					}
				},
				
				detail:(i)=>{					
					uni.navigateTo({						
						url:'../application_details/application_details',
						// success: function(res) {
						//     // 通过eventChannel向被打开页面传送数据
						//     res.eventChannel.emit('acceptDataFromOpenerPage', { data: i})
						//   }
						
					})
					store.commit('tangxiaoyun/setApplyData',i)
				},
				applyData: [1, 2, 3],
				getApplyData() {
					$http({
						url: "/Personalcenter/myapply/getone",
						data: {
							"mystate": data.mystate,
							"workid": data.workid,
						}
					}).then((res) => {				
						data.applyData = res.data.data
						
						
					})
				},
				
			})			
			onMounted(() => {
				data.getApplyData()
				
			})
			data.workid = computed(() => {
				return store.state.liujinchang.user.work_id
			})
			return {
				...toRefs(data)
			}
		}
	}
</script>

<style>
	.tablist {
		border: 1px solid white;
		border-radius: 10px;

		background-color: white;
		margin: 20rpx;
		padding: 20rpx 0 20rpx 20rpx;

	}

	.tablist>view {
		height: 60rpx;
		line-height: 60rpx;
	}

	.tablist>text {
		color: #2D8CF0;
		background-color: #EAF4FE;

	}

	page {
		background-color: #f2f2f2;
	}
</style>
